<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of TheMenu
 *
 * @author chenle
 */
class TheMenu {
    //put your code here

    public static function isSelected($need_uri){
        if(is_array($need_uri)){
            $isMatched = false;
            foreach ($need_uri as $value)
            {
                $hasStar = strpos($value,'*');
                if( $_SERVER['REQUEST_URI'] == $value 
                     || ($hasStar && substr($_SERVER['REQUEST_URI'],0,$hasStar) == substr($value,0,$hasStar) ))
                {
                    $isMatched = true;
                    break;        
                }
            }
            return $isMatched;
        }else{
            return ($need_uri == $_SERVER['REQUEST_URI']);
        }
    }

    public static function printSelect($need_uri,$inneed_uri=array()){
        return self::isSelected($need_uri) && !self::isSelected($inneed_uri) ?  'class="selected"' : '';
    }
    
    public static function printLink($name, $link, $need_uri=array(), $inneed_uri=array()){
        echo '<div class="menu_title2"><a href="'.$link.'" '.TheMenu::printSelect($need_uri, $inneed_uri).'>'.$name.'</a></div>';
    }    
    
    public static function printLinkNewWin($name, $link, $need_uri=array(), $inneed_uri=array()){
        echo '<div class="menu_title2"><a target="_blank" href="'.$link.'" '.TheMenu::printSelect($need_uri, $inneed_uri).'>'.$name.'</a></div>';
    }     

}
?>
